cc.Class({
    extends: cc.Component,

    properties: {
        playerNode:cc.Node,
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start() {
        this.collider = this.node.getComponent(cc.BoxCollider);
        console.log(this.collider.world);
        this.isCollision = false;
        this.updateCollisionSize();
    },
    updateCollisionSize: function () {
        let locPlayer_pos = this.node.getPosition();
        let worldPlayer_pos = this.node.convertToWorldSpaceAR(locPlayer_pos);
        let size = this.node.height; // 获取节点大小
        this.collider.size.height = size; // 更新碰撞体积为节点大小
        this.collider.world.aabb.y = worldPlayer_pos.y;
    },
    onCollisionEnter: function (other, self) {
        console.log("发生碰撞啦啦啦啦啦啦啦啦");
        this.isCollisionFn();
        let self_pos = self.node.getPosition();
        let other_pos = other.node.getPosition();
        let otherY = other.node.convertToWorldSpaceAR(other_pos);
        let selfY = self.node.convertToWorldSpaceAR(self_pos);
        if (selfY.y + self.node.height > otherY.y - other.node.height/2) {
          let reduceHeight = selfY.y + self.node.height - (otherY.y - other.node.height/2);
            self.node.height -= reduceHeight;

        }
        other.node.destroy();
    //    console.log(this.node.height); 
    },
    isCollisionFn:function(){
        this.isCollision = true;
    },
    update(dt) {
        let e = this;
        this.updateCollisionSize();
        if (game.isLasterAttack) {
            e.collider.onCollisionExit = function (other) {
                // 碰撞体离开其他物体时执行的操作
                console.log("碰撞结束");
                e.isCollision = false;
                // this.node.height = 1000;
            };
          
           
            // if (e.node.height < game.viewHeight && !e.isCollision){
            //     e.node.height+=dt*1000;
            // }
                
        }
        // this.node.on("size", this.updateCollisionSize());
    },
});
